// packageI/ecosphere_watercooler/water_use/no_card/no_card.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current_index: 0,
      list:[],
      device_no:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      device_no:options.device_no||''
    })
    this.data.device_no = options.device_no || "";
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  getData(){
    app._getNetWork({
      url:app.getNetAddresss('plugin.water-machine.frontend.consumer.no-card-goods.package'),
      data:{device_no:this.data.device_no},
      success:resdata=>{
        let {result,data,msg}  = resdata.data;
        if(result){
          console.log(data,"data===");
          this.setData({list:data.has_many_options})
        }else{
          app.tips(msg);
        }
      }
    })
  },
  pay(){
    let item = this.data.list[this.data.current_index];
    app._postNetWork({
      url:app.getNetAddresss("order.create"),
      data:{
        goods:[{goods_id:item.goods_id,total:1,option_id:item.id}]
      },
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?api=plugin.water-machine.frontend.consumer.no-card-goods.index&order_id=" + data.order_ids +'&device_no='+this.data.device_no
          })
        }else{
          app.tips(msg);
        }
      }
    })
  },
  goto() {
    wx.navigateTo({
      url: '/packageI/ecosphere_watercooler/water_use/history/history',
    })
  },
  choose(e) {
    this.setData({
      current_index:e.currentTarget.dataset.index,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})